package Java练习.方法的练习;

public class 复制数组 {
    public static void main(String[] args) {
        //定义一个数组
        int[] num={1,2,3,4,5,6,7,8,9};
       int[] nwe_num=copyOfRAnge(num,2,6);
        for (int i = 0; i < nwe_num.length; i++) {
            System.out.println(nwe_num[i]+" ");
        }

    }
    public static int[] copyOfRAnge(int[] arr,int from, int to ){
            //定义一个动态数组数组
            int[] num=new int[to-from];
            //遍历数组取出对应的值
        for (int i = 0; i < num.length; i++) {
            num[i]=arr[from+i-1];
        }
        return num;
        //方法二,虚拟定义一个索引
        

    }

}
